<?php
require_once '../../includefiles.php';
require_once '../../model/testimonials.php';

// create object
$testimonialObj = new Model_Testimonial();
 
## Check user login or not?
	$login_id = $_SESSION['getbids_id'];		
	
	if($login_id == ""){
	?> 
		<script type="text/javascript">		
		SITEROOT = "<?php echo SITE_URL ?>/";
		var redirectPage = SITEROOT + "signin/";	
		window.parent.location.href = redirectPage;		
		
        </script>
 	<?php
		exit;		
	} 
 
 ### When user want to edit the 
 
 if($_GET['id1'] == 'edit' && $_GET['id2']!=''){
	 $testimonialId    = $_GET['id2'];
	 $testimonialArray = $testimonialObj->Get_testimonial($testimonialId);
	  $smarty->assign('testimonialArray',$testimonialArray);
 }
 
### When user want to add new testimonial 
if(!empty($_POST))
{
	if(trim($_POST['description'])!='')
	{
			$addTestimonial                = array();
			$addTestimonial['user_id']     = $_SESSION['getbids_id'];
			$addTestimonial['description'] = html_entity_decode($_POST['description']);
			if($_POST['status'])
			{
				$addTestimonial['status']      = $_POST['status'];
			}else
			{
				$addTestimonial['status']      = '0';				
			}
			$addTestimonial['added_date']  = date("Y-m-d H:m:s");	

			if($_POST['edit_forum'] =='Update')
			{
				$testimonialId = $_POST['test_id'];
				$addTestimonial['id'] = $testimonialId;
				$testimonialObj->edit_Testimonial($addTestimonial,$addTestimonial['id']);
				if($_POST['status'])
				{
					$_SESSION['msg']="<div class='success_msg'style='margin-top:5px;margin-bottom: 20px;'><span>Testimonial updated successfully!.</span></div>";	
				}
				else
				{
					$_SESSION['msg']="<div class='success_msg'style='margin-top:5px;margin-bottom: 20px;'><span>Testimonial updated successfully!. It will be displayed after admin approval!.</span></div>";		
				}
			
			}
			else
			{
					$testimonialObj->add_Testimonial($addTestimonial);
					$_SESSION['msg']="<div class='success_msg'style='margin-top:5px;margin-bottom: 20px;'><span>Testimonial added successfully!. It will be displayed after admin approval!.</span></div>";				
			}
			
				?> 
		<script type="text/javascript">		
		SITEROOT = "<?php echo SITE_URL ?>/";
			
		var redirectPage = SITEROOT + "testimonials/mytestimonials/";	
		window.parent.location.href = redirectPage;		
		
        </script>
 	<?php
		exit;		
	}else{
		$_SESSION['msg'] = "<div class='error_msg' style='margin-top:5px;margin-bottom: 20px;'><span> Please fill up required field </span></div>";
	}
}
 
if($_SESSION['msg']){
		$smarty->assign("msg", $_SESSION['msg']);
		unset($_SESSION['msg']);
	}

$smarty->display(TEMPLATEDIR . 'modules/testimonial/add_testimonial.tpl');
?>